/* 校验文章上传的参数 */
const Response = require("../util/respanse.js")
/* 校验文章上传的参数 */
const verifyArticleParam = (req,res,next)=>{
    let fleg = false
    try {    
        const {article_title,article_content,article_description,article_author,lables,id} = req.body;     

        if(article_title=='' || article_content=='' || article_description=='' || article_author=='' || !Number.isInteger(id) ){
            fleg=true;
            Response.errorresponse(res,{
                code:400,
                msg:"参数错误2"
            })
        }
        if(!Array.isArray(lables)){
            fleg=true;
            Response.errorresponse(res,{
                code:400,
                msg:"标签类型错误"
            })

        }
       if(!fleg){
        next()
       }
    } catch (error) {
        
        if(!fleg){
            Response.errorresponse(res,{
                code:400,
                message:"返回失败",
                err:error
            })
        }
    }
}
/* 校验文章搜索的参数 */
const everfySherchprams = (req,res,next)=>{
   try {
    let {article_title,article_status,page,pageSize} = req.body
    if(!article_title|| !article_status  || !page || !pageSize){
        Response.errorresponse(res,{
            code:400,
            message:"参数错误"
        })
    }else{
        next()
    }
   } catch (error) {
    console.log(error);
   }
}
/* 添加足迹校验 */
const addpos = (req,res,next)=>{
    let {pos, article_id} = req.body
    let fleg = false;
    if(!pos || !article_id){
        fleg = true;
        Response.errorresponse(res,{
            code:400,
            msg:"参数错误"
        })
    }
    if(!fleg){
        next()
    }

}
module.exports={
    verifyArticleParam,
    everfySherchprams,
    addpos
}